package models;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import play.db.jpa.Model;
@Entity
public class Product extends Model {
	public String name;
	public int quantity;
	public int number_of_changes;
	public double price;
	public double total_price;
	public String smell;
	public LinkedList<Date> change_time_list ;	
	public String floor_type;
	//public long contract_id;

	@ManyToOne
	public Contract contract;

	
	
	public Product(String name,int quantity, int number_of_changes, double price,String smell, LinkedList<Date> change_time_list,String floor_type)
	{
		this.name=name;
		this.quantity=quantity;
		this.number_of_changes=number_of_changes;
		this.price=price;
		this.total_price = price*quantity;
		this.smell=smell;
		this.change_time_list=change_time_list;
		this.floor_type=floor_type;
	//	this.contract_id=contract_id;
		
		
	}
	public void addChangeTimes(Product p, int no_of_change_per_month, Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		if (no_of_change_per_month == 1) {
			Date d;
			cal.add(Calendar.DATE, 28);
			d = cal.getTime();
			System.out.println("date to be added :  " + d.toString());
			System.out.println(" 7mada "+d);
			p.change_time_list.addLast(d);
			for(int i =0;i<23;i++)
			{
				cal.setTime(p.change_time_list.getLast());
				cal.add(Calendar.DATE, 28);
				d = cal.getTime();
				p.change_time_list.addLast(d);											
			}
		}
		if (no_of_change_per_month == 2) {
			Date d;
			cal.add(Calendar.DATE, 14);
			d = cal.getTime();
			System.out.println("date to be added :  " + d.toString());
			System.out.println(" 7mada "+d);
			p.change_time_list.addLast(d);
			for(int i =0;i<23;i++)
			{
				cal.setTime(p.change_time_list.getLast());
				cal.add(Calendar.DATE, 14);
				d = cal.getTime();
				p.change_time_list.addLast(d);											
			}
		}
		
		if (no_of_change_per_month == 4) {
			Date d;
			cal.add(Calendar.DATE, 7);
			d = cal.getTime();
			System.out.println("date to be added :  " + d.toString());
			System.out.println(" 7mada "+d);
			p.change_time_list.addLast(d);
			for(int i =0;i<23;i++)
			{
				cal.setTime(p.change_time_list.getLast());
				cal.add(Calendar.DATE, 7);
				d = cal.getTime();
				p.change_time_list.addLast(d);											
			}
		}
		
		p.save();
	
	}

}
